package com.qfedu.lc.server.controller;


import com.qfedu.lc.common.param.PayAdd;
import com.qfedu.lc.common.util.JwtUtil;
import com.qfedu.lc.common.vo.R;
import com.qfedu.lc.server.service.UserWalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 6.用户钱包表 前端控制器
 * </p>
 *
 * @author wgz
 * @since 2023-11-06
 */
@RestController
@RequestMapping("/server/userWallet")
public class UserWalletController {


    @Autowired
    private UserWalletService userWalletService;

    /**
     * 余额充值业务
     * @param payAdd
     * @param httpServletRequest
     * @return
     */
    @RequestMapping("/create")
    public R create(@RequestBody PayAdd payAdd, HttpServletRequest httpServletRequest){
        // 1.判断数据
        if (payAdd==null){
            return R.fail("充值失败");
        }

        //userId
        String token = httpServletRequest.getHeader("Lctoken");
        //解析token
        Integer userId =Integer.valueOf(JwtUtil.parseToken(token,"id").toString());


        payAdd.setUserId(userId);
        payAdd.setType(2);


        return userWalletService.payWallet(payAdd);

    }

}

